﻿(function ($) {
    app.modals.CreateOrEditInvoiceModal = function () {

        var _classroomService = abp.services.app.invoice;
        var _modalManager;
        var _$form = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$form = _modalManager.getModal().find('form[name=ObjectForm]');
            _$form.validate();
        };

        this.save = function () {
            if (!_$form.valid()) {
                return;
            }

            var domainObject = _$form.serializeFormToObject();

            _modalManager.setBusy(true);
            _classroomService.createOrUpdateObject({
                invoice: domainObject //这个invoice名称应该和实体保持一致
            }).done(function (result) {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.setResult(result);
                _modalManager.close();
                abp.event.trigger('app.CreateOrEditModalSaved', result);
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };

        //if($("#InvoiceStartCode").text()!='')
        //{
        //    var s = parseInt($("#InvoiceStartCode").val());
        //    //$("#InvoiceStartCode").keyup(function () {
        //    //    $("#Account").val($("#SName").val());
        //    //})
        //    alert(s);
        //}
        
        $("#InvoiceEndCode").keyup(function () {
            var start = parseInt($("#InvoiceStartCode").val());
            var end = parseInt($("#InvoiceEndCode").val());
            var result = end - start + 1;
            $("#InvoiceNumber").val(result);
        })
    };
})(jQuery);